/*
 * Project it.battlehorse.rcp.ioc
 * Created on Apr 9, 2006
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * A copy of the LGPL is available also at
 * http://www.gnu.org/copyleft/lesser.html
 * 
 */
package it.battlehorse.ioc;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;

import static it.battlehorse.ioc.IOCConstants.*;

/**
 * The class visitor which recognizes annotations which mark serviceable objects
 * 
 * @author battlehorse
 * @since Apr 9, 2006
 */
public class ClassAnnotationVisitor extends ClassAdapter {
	
	private boolean matches = false;
	
	public ClassAnnotationVisitor(ClassVisitor cv) {
		super(cv);
	}
	
	@Override
	public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
		
		if (visible && desc.equals(SERVICEABLE_ANNOTATION)) {
			matches = true;		
		}
		
		return super.visitAnnotation(desc, visible);
	}
	
	@Override
	public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
		if (matches)
			return super.visitMethod(access, name, desc, signature, exceptions);
		else {
			return null;
		}
	}
	
	
}
